/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pkgjeudestrategie;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JButton;
import javax.swing.JFrame;

/**
 *
 * @author Alex
 */
public class FenetreMenuEsc extends JFrame {

    JButton btnResume = new JButton("Resume");
    JButton btnOptions = new JButton("Options");
    JButton btnStats = new JButton("Statisiques");
    JButton btnSave = new JButton("Sauvegarder");
    JButton btnLoad = new JButton("Charger");
    JButton btnQuitter = new JButton("Quitter");
    JButton[] btnTab={btnResume , btnOptions ,btnStats ,btnSave ,btnLoad ,btnQuitter};
    FenetreChoixQuitter fenetreQuit;
    FenetreMenuEsc menu=this;
    Jeu jeu;

    public FenetreMenuEsc(Jeu jeu) {
        //fenetreEscape.setBounds(40 / 100 * Fenetre.tailleX, 20 / 100 * Fenetre.tailleY,
        //20 / 100 * Fenetre.tailleX, 60 / 100 * Fenetre.tailleY);



        this.jeu = jeu;
        setTitle("Pause Menu");
        setLayout(new GridLayout(6, 0));
        for(JButton btn:btnTab){
            add(btn);
        }

        int tailleEscMenuX = 280;
        int tailleEscMenuY = 540;
        setSize(tailleEscMenuX, tailleEscMenuY);
        setLocation((int) (Fenetre.tailleX / 2 - getWidth() / 2), (int) (Fenetre.tailleY / 2 - getHeight() / 2));

        setUndecorated(true);
        setVisible(true);

        listen();
    }
public void setEnabled(boolean b){
    for(JButton btn:btnTab){
            btn.setEnabled(b);
        }
}
    private void listen() {
        this.addKeyListener(new KeyAdapter() {

            @Override
            public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                    dispose();

                }
            }
        });


        btnResume.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
                dispose();
                //pause

            }
        });

        btnQuitter.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) { 
                
            setEnabled(false);
                fenetreQuit = new FenetreChoixQuitter("Êtes-vous sûr de vouloir quitter ?",menu);
                
                
            }
        });

        btnSave.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
                jeu.sauvegarder();
                

            }
        });

        btnLoad.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
                jeu.chargerSauvegardes();

            }
        });
    }
}
